package de.justphil.tcg.tcgserver.websockets.messages;

import net.jcip.annotations.Immutable;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;

//omit 'null' values when serializing to json
@Immutable
@JsonSerialize(include = Inclusion.NON_NULL)
public class TCGProgressFragment {
	@JsonProperty
	private final String cmd;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final int s;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final long winner;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final long pId;
	
	//@JsonProperty
	//@JsonSerialize(include = Inclusion.NON_DEFAULT)
	//private final int cT;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final long cId;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final int[] pIds;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final int l;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final int at;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final int d;
	
	@JsonProperty
	@JsonSerialize(include = Inclusion.NON_DEFAULT)
	private final int ag;

	public TCGProgressFragment() {
		this.cmd		= null;
		this.s			= -1;
		this.winner		= 0;
		this.pId		= 0;
		this.cId 		= 0;
		this.pIds 		= null;
		this.l 			= Integer.MIN_VALUE;
		this.at			= Integer.MIN_VALUE;
		this.d			= Integer.MIN_VALUE;
		this.ag			= Integer.MIN_VALUE;
	}
	
	public TCGProgressFragment(String cmd) {
		this.cmd		= cmd;
		this.s			= -1;
		this.winner		= 0;
		this.pId		= 0;
		this.cId 		= 0;
		this.pIds 		= null;
		this.l 			= Integer.MIN_VALUE;
		this.at			= Integer.MIN_VALUE;
		this.d			= Integer.MIN_VALUE;
		this.ag			= Integer.MIN_VALUE;
	}
	
	public TCGProgressFragment(String cmd, int slot) {
		this.cmd		= cmd;
		this.s			= slot;
		this.winner		= 0;
		this.pId		= 0;
		this.cId 		= 0;
		this.pIds 		= null;
		this.l 			= Integer.MIN_VALUE;
		this.at			= Integer.MIN_VALUE;
		this.d			= Integer.MIN_VALUE;
		this.ag			= Integer.MIN_VALUE;
	}
	
	public TCGProgressFragment(String cmd, long winner) {
		this.cmd		= cmd;
		this.s			= -1;
		this.winner		= winner;
		this.pId		= 0;
		this.cId 		= 0;
		this.pIds 		= null;
		this.l 			= Integer.MIN_VALUE;
		this.at			= Integer.MIN_VALUE;
		this.d			= Integer.MIN_VALUE;
		this.ag			= Integer.MIN_VALUE;
	}
	
	public TCGProgressFragment(int s, long pId, long cId, int[] pIds, int l, int at, int d, int ag) {
		this.cmd		= null;
		this.s			= s;
		this.winner		= 0;
		this.pId		= pId;
		this.cId		= cId;
		this.pIds		= pIds;
		this.l			= l;
		this.at			= at;
		this.d			= d;
		this.ag			= ag;
	}

	@JsonIgnore
	public String getCommand() {
		return cmd;
	}

	@JsonIgnore
	public int getSlot() {
		return s;
	}

	public long getWinner() {
		return winner;
	}

	@JsonIgnore
	public long getPlayerId() {
		return pId;
	}

	@JsonIgnore
	public long getCardId() {
		return cId;
	}

	@JsonIgnore
	public int[] getPropertyTypes() {
		return pIds;
	}

	@JsonIgnore
	public int getLife() {
		return l;
	}

	@JsonIgnore
	public int getAttack() {
		return at;
	}

	@JsonIgnore
	public int getDefense() {
		return d;
	}

	@JsonIgnore
	public int getAgility() {
		return ag;
	}
	
	/* ############################################################################################ */
	/* ############################################################################################ */
	/* ############################################################################################ */
	
	public class Command {
		public static final String SELECT	= "select";
		public static final String RESUME	= "resume";
		public static final String WAIT		= "wait";
	}
	
	public class Winner {
		public static final String DRAW		= "d";
	}
}
